﻿using UnityEngine;
using System.Collections;

public class SwingableWeapon : MeleeWeapon {
	
	private const string kAnimationSwingRight = "swingRightTrigger";
	private const string kAnimationSwingLeft = "swingLeftTrigger";
	private const string kAnimationSwingUp = "swingUpTrigger";
	private const string kAnimationSwingDown = "swingDownTrigger";
	
	private Animator swingAnimator;

	// Use this for initialization
	void Start () {
		InitWeapon();

		swingAnimator = this.GetComponent<Animator>();
	}
	
	// Update is called once per frame
	void Update () {
		UpdateWeapon();
	}

	public override void OnAttack(Vector2 direction)
	{
		if (direction.y == 0)
		{
			//moving in X axis
			if (direction.x > 0)
			{
				swingAnimator.SetTrigger(kAnimationSwingRight);
			}
			else 
			{
				swingAnimator.SetTrigger(kAnimationSwingLeft);
			}
		}
		else if (direction.x == 0)
		{
			if (direction.y > 0)
			{
				swingAnimator.SetTrigger(kAnimationSwingUp);
			}
			else
			{
				swingAnimator.SetTrigger(kAnimationSwingDown);
			}
		}	
	}
	
	public override void OnReload()
	{
		
	}

	void OnCollisionEnter2D(Collision2D collision)
	{
		if (collision.collider)
		{
			Entity entityComp = collision.collider.gameObject.GetComponent<Entity>();
			entityComp.Hp--;
		}
	}
	
}
